package com.kksoft.readcm.views;

import com.kksoft.readcm.pro.R;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.view.GestureDetector;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;

public class ErrorScreen extends LinearLayout
{
  private x a;
  private ProgressBar b;
  private TextView c;
  private TextView d;
  private TextView e;
  private Button f;
  private GestureDetector g;

  public ErrorScreen(Context context, AttributeSet attributeset)
  {
      super(context, attributeset);
      ((Activity)getContext()).getLayoutInflater().inflate(R.layout.error_screen, this, true);
      b = (ProgressBar)findViewById(R.id.error_progress);
      d = (TextView)findViewById(R.id.error_page_title);
      c = (TextView)findViewById(R.id.error_title);
      e = (TextView)findViewById(R.id.error_message);
      f = (Button)findViewById(R.id.error_button);
      g =  new GestureDetector(new v(this));
      b.setOnTouchListener(new OnTouchListener(){

		@Override
		public boolean onTouch(View v, MotionEvent event) {
			// TODO Auto-generated method stub
			boolean flag;
	        if(ErrorScreen.b(ErrorScreen.this).onTouchEvent(event))
	            flag = true;
	        else
	            flag = false;
	        return flag;
		}
    	  
      });
      
      c.setOnTouchListener(new OnTouchListener(){

  		@Override
  		public boolean onTouch(View v, MotionEvent event) {
  			// TODO Auto-generated method stub
  			boolean flag;
  	        if(ErrorScreen.b(ErrorScreen.this).onTouchEvent(event))
  	            flag = true;
  	        else
  	            flag = false;
  	        return flag;
  		}
      	  
        });
      e.setOnTouchListener(new OnTouchListener(){

    		@Override
    		public boolean onTouch(View v, MotionEvent event) {
    			// TODO Auto-generated method stub
    			boolean flag;
    	        if(ErrorScreen.b(ErrorScreen.this).onTouchEvent(event))
    	            flag = true;
    	        else
    	            flag = false;
    	        return flag;
    		}
        	  
          });
  }
  
  static x a(ErrorScreen errorscreen)
  {
      return errorscreen.a;
  }

  static GestureDetector b(ErrorScreen errorscreen)
  {
      return errorscreen.g;
  }

  public final void a()
  {
    this.b.setVisibility(8);
    this.d.setVisibility(8);
    this.c.setVisibility(8);
    this.e.setVisibility(8);
    this.f.setVisibility(8);
    this.f.setOnClickListener(null);
  }

  public final void a(View.OnClickListener paramOnClickListener)
  {
    this.f.setOnClickListener(paramOnClickListener);
  }

  public final void a(x paramx)
  {
    this.a = paramx;
  }

  public final void a(String paramString)
  {
    this.c.setText(paramString);
    this.c.setVisibility(0);
  }

  public final void b()
  {
    this.b.setVisibility(0);
  }

  public final void b(String paramString)
  {
    this.d.setText(paramString);
    this.d.setVisibility(0);
  }

  public final void c(String paramString)
  {
    this.e.setText(paramString);
    this.e.setVisibility(0);
  }

  public final void d(String paramString)
  {
    this.f.setText(paramString);
    this.f.setVisibility(0);
  }

  protected void onRestoreInstanceState(Parcelable paramParcelable)
  {
    Bundle localBundle = (Bundle)paramParcelable;
    Parcelable localParcelable = localBundle.getParcelable("superState");
    super.onRestoreInstanceState(localParcelable);

    this.c.setText(localBundle.getString("title"));
    this.e.setText(localBundle.getString("message"));
    this.f.setText(localBundle.getString("buttonText"));
    this.b.setVisibility(localBundle.getInt("progressVisible"));
    this.c.setVisibility(localBundle.getInt("titleVisible"));
    this.e.setVisibility(localBundle.getInt("messageVisible"));
    this.f.setVisibility(localBundle.getInt("buttonTextVisible"));
  }

  protected Parcelable onSaveInstanceState()
  {
    Bundle localBundle = new Bundle();
    Parcelable localParcelable = super.onSaveInstanceState();
    localBundle.putParcelable("superState", localParcelable);
    localBundle.putString("title", this.c.getText().toString());
    localBundle.putString("message", this.e.getText().toString());
    localBundle.putString("buttonText", this.f.getText().toString());
    localBundle.putInt("progressVisible", this.b.getVisibility());
    localBundle.putInt("titleVisible", this.c.getVisibility());
    localBundle.putInt("messageVisible", this.e.getVisibility());
    localBundle.putInt("buttonTextVisible", this.e.getVisibility());
    return localBundle;
  }
}